package ru.reaperoq.taskmanager.models

import jakarta.persistence.*
import org.hibernate.annotations.CreationTimestamp
import java.time.LocalDateTime
import java.util.UUID

@Entity(name = "lists")
open class TaskList(
    @Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
    open val id: Long? = null,
    @Column(length = 70)
    open val title: String,
    @Column(insertable = false, updatable = false)
    @CreationTimestamp
    open val createdAt: LocalDateTime = LocalDateTime.now(),
    @ManyToOne
    @JoinColumn(nullable = false)
    open val author: User,

    @Column
    open val sharedId: UUID? = null,

    @OneToMany(cascade = [(CascadeType.ALL)], mappedBy = "list", fetch = FetchType.LAZY)
    open val tasks: MutableSet<Task> = mutableSetOf(),

    @OneToMany(cascade = [(CascadeType.ALL)], mappedBy = "list", fetch = FetchType.LAZY)
    open val timetables: MutableSet<Timetable> = mutableSetOf()
)